export default function() {
    return {
        data() {
            return {
                dialogDeviceVisible: false,
                checkAll: false,
                checkedDevice: [],
                deviceList: [],
                deviceModelArr: [],
                isIndeterminate: true,

                versionList: [],
                checkVersion: [],
                dialogDeviceVersionVisible: false,
                
            }
        },
        methods: {
            showDeviceDialog(){
                this.dialogDeviceVisible = true;
            },
            handleCheckAllChange(val) {
                this.checkedDevice = val ? this.deviceList : [];
                this.isIndeterminate = false;
            },
            handleCheckedDeviceChange(value) {
                this.record.limitDevice = value;
                let checkedCount = value.length;
                this.checkAll = checkedCount === this.deviceList.length;
                this.isIndeterminate = checkedCount > 0 && checkedCount < this.deviceList.length;
            },
            openDialogDevice(){
                this.checkedDevice = this.record.limitDevice ? this.record.limitDevice : [];
            },
            filterCheckDeiveName(vals){ //过滤出设备名数组
                let tempArr = [];
                if(vals){
                    vals.forEach(item => {
                        this.deviceList.forEach(item02 => {
                            if(item === item02.deviceModel){
                                tempArr.push(item02.deviceName)
                            }
                        });
                    });
                }
                return tempArr;
            },
            filterCheckDeiveModel(vals){ //过滤出设备名类型
                let tempArr = [];
                JSON.parse(vals).forEach(item => {
                    this.deviceList.forEach(item02 => {
                        if(item === item02.deviceName){
                            tempArr.push(item02.deviceModel)
                        }
                    });
                });
                return tempArr;
            },

            showDeviceVersionDialog(){
                this.dialogDeviceVersionVisible = true;
            },
            handleCheckedDeviceVersionChange(value){
                this.record.limitVersion = value;
            },
            openDialogDeviceVersion(){
                let limitVersion = this.record.limitVersion;
                this.checkVersion = limitVersion ? (typeof limitVersion === 'string' ? JSON.parse(limitVersion) : limitVersion) : [];
            },

            filterLimitDevice(vals){
                if(vals && vals.length !== 0){
                    let str = "";
                    vals.forEach(item => {
                        str += '，' + item
                    });
                    return str.slice(1);
                }
                return '无';
            },
            filterLimitVersion(vals){
                if(vals && vals.length !== 0){
                    let str = "";
                    vals.forEach(item => {
                        str += '，' + item
                    });
                    return str.slice(1);
                }
                return  '无';
            }
        },
    }
}